export const findComponent = (parent, componentName) => {
  let component
  find(parent)
  function find(parent) {
    if (!parent) return
    if (parent.$attrs.hasOwnProperty(componentName)) {
      component = parent
      return
    } else {
      find(parent.$parent)
    }
  }
  return component
}

export const findComponentDataField = (parent, fieldKey) => {
  let dataField
  find(parent)
  function find(parent) {
    if (!parent) return
    if (parent[fieldKey]) {
      dataField = parent[fieldKey]
      return
    } else {
      find(parent.$parent)
    }
  }
  return dataField
}

export const findComponentAttrsField = (parent, fieldKey) => {
  let attrsField
  find(parent)
  function find(parent) {
    if (!parent) return
    if (parent.$attrs[fieldKey]) {
      attrsField = parent.$attrs[fieldKey]
      return
    } else {
      find(parent.$parent)
    }
  }
  return attrsField
}

export const hasComponentAttrsField = (parent, fieldKey) => {
  let has
  find(parent)
  function find(parent) {
    if (!parent) return
    if (parent.$attrs.hasOwnProperty(fieldKey)) {
      has = true
      return
    } else {
      find(parent.$parent)
    }
  }
  return has
}